<template>
	<div>
	    {{count}}
	</div>
</template>
<script>
	export default {
		name: 'baseCountDown',
		props: {
			
		},
	
		data() {
			return {
				time:'',
				count: '', //倒计时
				seconds: '' // 10天的秒数
			}
		},
		created() {
			this.Time() //调用定时器
		},
	
		methods:{
		// 天 时 分 秒 格式化函数
				countDown() {
					let d = parseInt(this.seconds / (24 * 60 * 60))
					
					d = d < 10 ? "0" + d : d
					let h = parseInt(this.seconds / (60 * 60) % 24);
					h = h < 10 ? "0" + h : h
					let m = parseInt(this.seconds / 60 % 60);
					m = m < 10 ? "0" + m : m
					let s = parseInt(this.seconds % 60);
					s = s < 10 ? "0" + s : s;
					
					this.count = m + ':' + s 
				},
				//定时器没过1秒参数减1
				Time() {
				  this.time=setInterval(() => {
						if(!this.seconds){
							 clearInterval(this.time);        
							this.$emit('end')
						}else{
							this.seconds -= 1
							this.countDown()
						}
					
					}, 1000)
				},
			
		}
	}
</script>

<style scoped>

</style>
